using UnityEngine;

public class WaterCamera : MonoBehaviour
{
	public float posYWater = -0.5f;

	public float waterStartFogDistance = 5f;

	public float waterEndFogDistance = 60f;

	public float waterFogDensity = 0.5f;

	private Camera curCamera;

	private CameraClearFlags startClearFlag;

	private Color startFogColor;

	private float startFogStartDistance;

	private float startFogEndDistance;

	private float startFogDensity;

	private bool predCamUnderWater;

	private void Start()
	{
		curCamera = GetComponent<Camera>();
		float[] array = new float[32];
		array[15] = 500f;
		curCamera.layerCullDistances = array;
		if (Device.isWeakDevice)
		{
			RenderSettings.fogMode = FogMode.Linear;
			RenderSettings.fogDensity = 0.5f;
			RenderSettings.fogStartDistance = curCamera.farClipPlane - 50f;
			RenderSettings.fogEndDistance = curCamera.farClipPlane;
		}
		startClearFlag = curCamera.clearFlags;
		startFogColor = RenderSettings.fogColor;
		startFogStartDistance = RenderSettings.fogStartDistance;
		startFogEndDistance = RenderSettings.fogEndDistance;
		startFogDensity = RenderSettings.fogDensity;
	}

	private void LateUpdate()
	{
		if (GameController.instance != null && GameController.instance.curTypeGame == TypeGame.RocketLeague)
		{
			return;
		}
		bool flag = false;
		if (GameController.instance.playerScript != null && !GameController.instance.playerScript.inCar && !GameController.instance.playerScript.inHelic)
		{
			if (curCamera.transform.position.y < -0.5f && GameController.instance.playerScript.inWater)
			{
				flag = true;
			}
		}
		else if (GameController.instance.carScript != null && GameController.instance.carScript.inWater && GameController.instance.playerScript.inCar && curCamera.transform.position.y < -0.5f)
		{
			flag = true;
		}
		if (predCamUnderWater != flag)
		{
			if (flag)
			{
				curCamera.clearFlags = CameraClearFlags.Color;
				RenderSettings.fogColor = curCamera.backgroundColor;
				RenderSettings.fogStartDistance = waterStartFogDistance;
				RenderSettings.fogEndDistance = waterEndFogDistance;
				RenderSettings.fogDensity = waterFogDensity;
				predCamUnderWater = true;
			}
			else
			{
				curCamera.clearFlags = startClearFlag;
				RenderSettings.fogColor = startFogColor;
				RenderSettings.fogStartDistance = startFogStartDistance;
				RenderSettings.fogEndDistance = startFogEndDistance;
				RenderSettings.fogDensity = startFogDensity;
				predCamUnderWater = false;
			}
		}
	}
}
